local skel = fk.CreateSkill {
  name = "lb__luandie",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable {
  ["lb__luandie"] = "乱蝶",
  [":lb__luandie"] = "<b>锁定技</b>，你发动<a href=':lb__zaixian'><font color='red'>〖再现〗</font></a>时改为执行未选择项，且你的手牌上限翻倍，回合内第一张黑【杀】不计入次数限制。",

  ["#lb__luandie_maxcards"] = "乱蝶",

  ["lb__luandie1"] = "",
  ["lb__luandie2"] = "",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and player.phase ~= Player.NotActive and
        data.card.color == Card.Black and data.card.trueName == "slash" and not data.extraUse then
      local event_id = player.room.logic:getCurrentEvent().id
      return (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data
        return use.card.color == Card.Black and use.card.trueName == "slash" and
            use.from == player and e.id ~= event_id
      end, Player.HistoryTurn) == 0)
    end
  end,
  on_use = function(self, event, target, player, data)
    player:addCardUseHistory(data.card.trueName, -1)
    data.extraUse = true
  end,
})

--- 获取玩家手牌上限。
---@return integer
local getMaxCards = function(self, s)
  local baseValue = math.max(self.hp, 0)

  local status_skills = Fk:currentRoom().status_skills[MaxCardsSkill] or Util.DummyTable
  local max_fixed = nil
  for _, skill in ipairs(status_skills) do
    if skill ~= s then --排除
      local f = skill:getFixed(self)
      if f ~= nil then
        max_fixed = max_fixed and math.max(max_fixed, f) or f
      end
    end
  end

  if max_fixed then baseValue = math.max(max_fixed, 0) end

  for _, skill in ipairs(status_skills) do
    local c = skill:getCorrect(self)
    baseValue = baseValue + (c or 0)
  end

  return math.max(baseValue, 0)
end

skel:addEffect("maxcards", {
  fixed_func = function(self, player)
    if player:hasSkill(skel.name) then
      return getMaxCards(player, self) * 2
    end
  end
})

return skel
